﻿using BigEgg.Framework.Foundation;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace FMStudio.Domain.SQLite
{
    [MetadataType(typeof(IPayType))]
    public partial class PayType : IPayType, IDataErrorInfo
    {
        #region Implement IDataErrorInfo Interface
        [NonSerialized]
        private readonly DataErrorInfoSupport dataErrorInfoSupport;

        string IDataErrorInfo.Error { get { return this.dataErrorInfoSupport.Error; } }

        string IDataErrorInfo.this[string memberName] { get { return this.dataErrorInfoSupport[memberName]; } }
        #endregion


        public PayType()
        {
            this.dataErrorInfoSupport = new DataErrorInfoSupport(this);

            //  Default value
            this.Name = string.Empty;

            this.CurrencyReference.AssociationChanged += CurrencyReferenceAssociationChanged;
        }


        #region Implement IPayType Interface
        ICurrency IPayType.Currency
        {
            get { return this.Currency; }
            set { this.Currency = value as Currency; }
        }
        #endregion


        #region Private Methods
        private void CurrencyReferenceAssociationChanged(object sender, CollectionChangeEventArgs e)
        {
            // The navigation property doesn't support the PropertyChanged event. We have to raise it ourselves.
            OnPropertyChanged("Currency");
            this.CurrencyID = this.Currency.ID;
        }
        #endregion
    }
}
